﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DB_QLSV.BusinessClassLibrary
{
    public class KhoaHocBUS
    {
        private static QLSVDataContext db = new QLSVDataContext();
        public static bool ThemKhoaHoc(KhoaHoc khoahoc)
        {
            try
            {
                db.KhoaHocs.InsertOnSubmit(khoahoc);
                db.SubmitChanges();
            }
            catch
            {
                //conflict primary key - the item is exist
                return false;
            }
            return true;
        }
        public static bool XoaKhoaHoc(string idkhoahoc)
        {
            try
            {
                KhoaHoc old = db.KhoaHocs.Single(kh => kh.makh == idkhoahoc);
                db.KhoaHocs.DeleteOnSubmit(old);
                db.SubmitChanges();
            }
            catch
            {
                // the item is not exist
                return false;
            }
            return true;
        }
        public static bool CapNhatKhoaHoc(string id,KhoaHoc khoahoc)
        {
            try
            {
                KhoaHoc old = db.KhoaHocs.Single(kh => kh.makh == id);
                old.nam=khoahoc.nam;
                old.ngaybatdau = khoahoc.ngaybatdau;
                old.ngayketthuc = khoahoc.ngayketthuc;
                db.SubmitChanges();
            }
            catch
            {
                // the item is not exist
                return false;
            }
            return true;
        }
        public static List<KhoaHoc> LayDanhSach()
        {
            return db.KhoaHocs.ToList();
        }
    }
}
